
import { createRouter, createWebHistory } from 'vue-router'
// import Home from "@/views/Home.vue";
// import Audit from "@/views/process/Audit.vue";
// import Extract from "@/views/process/Extract.vue";
// import Inlay from "@/views/process/Inlay.vue";
// import Translate from "@/views/process/Translate.vue";

// import User from "@/views/system/User.vue";
// import Role from "@/views/system/Role.vue";
// import Menu from "@/views/system/Menu.vue";

// import Comic from "@/views/published/Comic.vue";
// import Posted from "@/views/personal/Posted.vue";

// import Login from "@/views/Login.vue";
const routes = [{
	path: "/",
	name: "首页",
	component: () => import('@/views/Home.vue'),
	children: [{
		path: "/process/audit",
		name: "原图审核",
		component: () => import('@/views/process/Audit.vue')
	},
	{
		path: "/process/extract",
		name: "提炼日文",
		component: () => import('@/views/process/Extract.vue')
	}
		, {
		path: "/process/translate",
		name: "翻译",
		component: () => import('@/views/process/Translate.vue')
	}, {
		path: "/process/inlay",
		name: "嵌字",
		component: () => import('@/views/process/Inlay.vue')
	},
	{
		path: "/system/user",
		name: "用户管理",
		component: () => import('@/views/system/User.vue')
	},
	{
		path: "/system/role",
		name: "角色管理",
		component: () => import('@/views/system/Role.vue')
	}, {
		path: "/system/menu",
		name: "页面权限管理",
		component: () => import('@/views/system/Menu.vue')
	},
	{
		path: "/published/comic",
		name: "已发布漫画",
		component: () => import('@/views/published/Comic.vue')
	}
	]
}
	,
{
	path: "/login",
	name: "Login",
	component: () => import('@/views/Login.vue')
}
];

const router = createRouter({
	// createWebHashHistory
	history: createWebHistory(process.env.BASE_URL),
	routes,
})

router.beforeEach(async (to) => {
	//遍历meta改变title
	if (to.meta.title) {
		document.title = to.meta.title;
	}
	if (location.port !== '3000') {
		let token = localStorage.getItem('user')
		if (
			// 检查用户是否已登录
			!token &&
			// ❗️ 避免无限重定向
			to.name !== 'Login' && to.name !== 'Register'
		) {
			// 将用户重定向到登录页面
			return { name: 'Login' }
		}
	}
})




export default router;
